<template>
  <div class="dizhi">
    <div>
      <span>
        <input
          @click="x"
          :value="item.id"
          v-if="isxianshi"
          name="Fruit"
          v-model="xuan"
          type="radio"
        />
        <i v-else class="iconfont icon-duihao2"></i>
      </span>
      <span>送货至:</span>
      <span>{{item.name}}</span>
      <span>{{item.prov}}</span>
      <span>{{item.city}}</span>
      <span>{{item.district}}</span>
      <span>{{item.dizhixiangqing}}</span>
      <span>
        <span>
          <span v-if="!item.phone">
            固定电话
            <span>{{item.quma+"-"+item.telephone}}</span>
          </span>
          <span v-else>
            手机
            <span>{{item.phone}}</span>
          </span>
        </span>
      </span>
      <span v-if="item.morenis==1&&isxianshi" class="hui">默认地址</span>
    </div>
    <div class="lvse" v-if="isxianshi">
      <span v-if="item.morenis!=1" @click="shezhimoren(item.id)" class="huang">设置默认地址</span>
      <span @click="xiugai(item.id)">修改</span>
      <span @click="shanchu($event,item.id)">删除</span>
    </div>
  </div>
</template>

<script>
import "@/assets/font/iconfont.css";
import axios from "axios";
export default {
  props: ["item", "isxianshi","shiyong"],
  data() {
    return { xuan: 1 };
  },
  mounted(){
    if(this.item.morenis=="1"){
      this.$emit("xianzhe",this.item.id);
      this.xuan = this.item.id
    }
  },
  methods: {
    x() {
      var _this = this;
      setTimeout(function() {
        _this.$emit("xianzhe", _this.xuan);
        localStorage.xuan = _this.xuan
      }, 20);
    },
    shanchu(e, i) {
      // var _this = this;
      var url = this.$store.state.url;
      axios.post(url + "dizhishanchu", { id: i }).then(
        res => {
          // 成功回调
          if (res.data.code == 300) {
            window.console.log(res.data);
            alert("删除成功");
            e.target.parentElement.parentElement.remove();
          } else {
            alert("删除失败");
          }
        },
        res => {
          window.console.log(res);
          alert("删除失败");
          // 错误回调
        }
      );
    },
    xiugai(e) {
      this.$emit("xiugai", e);
    },
    shezhimoren(e) {
      var _this = this;
      var url = this.$store.state.url;
      axios.post(url + "shezhimoren", { id: e }).then(
        res => {
          // 成功回调
          if (res.data.code == "300") {
            window.console.log(res.data);
            _this.$emit("shezhimoren");
            _this.$emit("xianzhe", _this.item.id);
            alert("设置成功");
          } else {
            alert("设置失败");
          }
        },
        res => {
          window.console.log(res);
          alert("设置失败");
          // 错误回调
        }
      );
    }
  },
  components: {},
  watch: {
    item() {
      this.xuan=this.shiyong
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.dizhi .iconfont {
  color: #498e3d;
}
.dizhi {
  display: flex;
  justify-content: space-between;
  background-color: #f4fff2;
  border: 1px solid #e5e5e5;
  padding: 0.4rem;
  font-size: 0.8rem;
  margin-bottom: 0.6rem;
}
.dizhi > div > span {
  padding: 0px 0.2rem;
}
.dizhi .lvse > span {
  color: #498e3d;
  padding: 0px 0.5rem;
  cursor: pointer;
}
.dizhi .lvse > span.huang {
  color: #f08a10;
}
.hui {
  color: #aaa;
}
</style>
